package com.vertx.mall.rest;

import com.vertx.web.annotation.RequestMethod;
import com.vertx.web.annotation.Rest;
import com.vertx.web.annotation.RestApi;
import com.vertx.web.annotation.RestRouter;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

/**
 * 描述: 主页
 * 创建人:hzw
 * 创建时间: 2018/4/17 18:02
 **/

@Rest
@RestRouter(path = "/api")
public class IndexRest {

    @RestApi(path="/id",method=RequestMethod.GET)
    public void test(RoutingContext routingContext,Vertx vertx){
        JsonObject _json = new JsonObject();
        _json.put("key","index");
        vertx.eventBus().send("indexStore",_json,res->{
            if(res.failed()){
                routingContext.response().end(res.cause().getMessage());
            }else{
                routingContext.response().end(res.result().body().toString());
            }
        });

    }

    @RestApi(path = "/test2",method = RequestMethod.POST)
    public void test2(RoutingContext routingContext,Vertx vertx){
        JsonObject _json = new JsonObject();
        _json.put("key","index");
        routingContext.response().end("ok");
    }

    @RestApi(path = "/test3",method = RequestMethod.GET)
    public void test3(RoutingContext routingContext,Vertx vertx){
        JsonObject _json = new JsonObject();
        _json.put("key","index");
        routingContext.response().end("ok");
    }

}
